package com.egu.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.CustomerCare;
import com.egu.service.CustomerCareService;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("customerCare")
public class CustomerCareController {

	@Autowired
	private CustomerCareService customerCareService;

	@RequestMapping("listUI")
	public String listUI() {
		return "customerCare/listUI";
	}
	
	
	@RequestMapping("/getList")
	@ResponseBody
	public RequestPageVo<CustomerCare> getList(@ModelAttribute(value = "param") PageParam param, CustomerCare customerCare) {
		RequestPageVo<CustomerCare> vo = customerCareService.getList(param, customerCare);
		return vo;
	}

	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public RequestResultVo<CustomerCare> saveOrUpdate(CustomerCare customerCare) {
		RequestResultVo<CustomerCare> result = new RequestResultVo<CustomerCare>();
		if (customerCare != null) {
			return customerCareService.saveOrUpdate(customerCare);
		} else {
			result.setSuccess(false);
		}
		return result;
	}

	@RequestMapping("/deleteDataById")
	public @ResponseBody RequestResultVo<CustomerCare> deleteDataById(@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<CustomerCare> result = new RequestResultVo<CustomerCare>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("数据库操作异常");
			return result;
		}
		result = customerCareService.deleteDataById(id);
		return result;
	}
}
